<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    String static_path = path + "/static/alpha";
    String x_admin_path = path + "/static/X-admin-2.3";
%>
<html>
<head>
    <title>部门管理</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">

    <!-- X-admin -->
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <script type="text/javascript" src="<%=x_admin_path%>/jquery-3.2.1.min.js"></script>
    <link rel="stylesheet" href="<%=x_admin_path%>/css/font.css">
    <link rel="stylesheet" href="<%=x_admin_path%>/css/xadmin.css">
    <script type="text/javascript" src="<%=x_admin_path%>/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="<%=x_admin_path%>/js/xadmin.js"></script>
</head>
<body class="hold-transition sidebar-mini">
<div class="wrapper">
    <!-- 文件头 -->
    <jsp:include page="/manage/inc/head"></jsp:include>

    <!-- 侧边栏 -->
    <jsp:include page="/manage/inc/sidebar"></jsp:include>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <div class="container-fluid">
                <div class="row mb-2">
                    <div class="col-sm-6">
                        <h1>部门管理</h1>
                    </div>
                </div>
            </div><!-- /.container-fluid -->
        </section>

        <section class="content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-12">
                        <!-- Main content -->
                        <div class="invoice p-3 mb-3">
                            <xblock style="background-color:white;">
                                <button class="layui-btn" data-method="up_depart" onclick="insert()" style="width:100px;"><i class="layui-icon"></i>添加部门</button>
                                <span class="x-right" style="line-height:40px">共有数据：${requestScope.departNum} 条</span>
                            </xblock>

                            <!-- Table row -->
                            <div class="row">
                                <div class="col-12 table-responsive">
                                    <table class="table table-striped">
                                        <thead>
                                        <tr>
                                            <th>部门编号</th>
                                            <th>部门名称</th>
                                            <th>部门经理</th>
                                            <th>预编人数</th>
                                            <th>部门备注</th>
                                            <th>操作</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                            <c:forEach items="${requestScope.departmentList}" var="list">
                                                <tr>
                                                    <td>${list.id}</td>
                                                    <td>${list.departmentName}</td>
                                                    <td>${list.user.name}</td>
                                                    <td>${list.peopleNum}</td>
                                                    <td>
                                                        <button class="layui-btn" data-method="up_depart" onclick="x_admin_show('${list.departmentName}备注','<%=path%>/manage/department/remark?departmentId=${list.id}')" style="width:100px; height:30px; line-height:8px; padding-left:10px;">
                                                            <i class="layui-icon"></i>${list.departmentName}备注</button>
                                                    </td>
                                                    <td class="td-manage">
                                                        <a title="编辑" onclick="update(${list.id})" href="javascript:;">
                                                            <i class="layui-icon"></i>
                                                        </a>
                                                        <a title="删除" onclick="member_del(this,${list.id})" href="javascript:;">
                                                            <i class="layui-icon"></i>
                                                        </a>
                                                    </td>
                                                </tr>
                                            </c:forEach>
                                        </tbody>
                                    </table>
                                </div>
                                <!-- /.col -->
                            </div>
                        </div>
                        <!-- /.invoice -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.container-fluid -->
        </section>
        <!-- /.content -->
    </div>

    <!-- 底部包含 -->
    <jsp:include page="/manage/inc/foot"></jsp:include>

</div>
<!-- AdminLTE App -->
<script src="<%=static_path%>/dist/js/adminlte.min.js"></script>

<script>
    /**部门添加*/
    function insert() {
        //iframe层
        parent.layer.open({
            type: 2,
            title: '添加部门',
            shadeClose: false, //点击遮罩关闭
            shade: 0.8,
            area: ['90%', '95%'],
            maxmin: true,
            closeBtn: 1,
            content: ['<%=path%>/manage/department/insert', 'yes'], //iframe的url，yes是否有滚动条
            //yes: function (index, layero) {
            //    alert(index);
            //    alert(layero);
            //},
            end: function () {
                location.reload();
            }

        });
    }

    /**部门修改*/
    function update(departId) {
        //iframe层
        parent.layer.open({
            type: 2,
            title: '修改部门',
            shadeClose: false, //点击遮罩关闭
            shade: 0.8,
            area: ['90%', '95%'],
            maxmin: true,
            closeBtn: 1,
            content: ['<%=path%>/manage/department/update?departId='+departId, 'yes'], //iframe的url，yes是否有滚动条
            //yes: function (index, layero) {
            //    alert(index);
            //    alert(layero);
            //},
            end: function () {
                location.reload();
            }

        });
    }

    /**用户-删除*/
    function member_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){

            $.ajax({
                url:"<%=path%>/manage/department/delete",
                type:"post",
                data:{departId:id},
            });

            //发异步删除数据
            $(obj).parents("tr").remove();
            layer.msg('已删除!',{icon:1,time:1000});
        });
    }
</script>
</body>
</html>
